<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
</head>

<body>
    <div id="app"></div>
    <script type="text/babel">
        class Life extends React.Component {
            state = { sum: 0 }
            add = () => {
                const { sum } = this.state
                this.setState({
                    sum: sum + 1
                })

            }
            death = () => {
                ReactDOM.unmountComponentAtNode(document.getElementById("app"))
            }
            componentDidMount() {
                console.log(1);
            }
            componentWillUnmonunt() {
                console.log(3);
            }
            render() {
                const { sum } = this.state
                return (
                    <div>
                        <h4>和{sum}</h4>
                        <button onClick={this.add}>按钮</button>
                        <button onClick={this.death}>卸载组件</button>
                    </div>
                )
            }
        }

        ReactDOM.render(<Life />, document.getElementById('app'))
        
    </script>
</body>

</html>